package _interview150;

import java.util.ArrayList;
import java.util.List;

/**
 * 6. N 字形变换
 */
public class No6 {
    public String convert(String s, int numRows) {
        if (numRows == 1) return s;
        List<StringBuilder> list = new ArrayList<>();
        for (int i = 0; i < numRows; i++) {
            list.add(new StringBuilder());
        }
        int i = 0, inc = -1;
        for (char c : s.toCharArray()) {
            list.get(i).append(c);
            if (i == 0 || i == numRows - 1) inc = -inc;
            i += inc;
        }
        StringBuilder ans = new StringBuilder();
        for (StringBuilder sb : list) {
            ans.append(sb);
        }
        return ans.toString();
    }
}
